package controller.admin;

import model.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 获取用户数据
 */
@WebServlet(name = "AdminUserEditshowServlet", value = "/admin/user_editshow")
public class AdminUserEditshowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserService us = new UserService();
        String userId = request.getParameter("id");
        //没有参数
        if (!(userId != null && !"".equals(userId))) {
            response.sendRedirect(request.getHeader("Referer"));
            return;
        }

        //获取用户信息
        User user = us.getUserById(Integer.parseInt(userId));
        request.setAttribute("u", user);
        request.getRequestDispatcher("user_edit.jsp").forward(request, response);
    }
}
